package com.example.sangong.http;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
@ApiModel("通用返回结果实体")
public class Result<T> {
    @ApiModelProperty(value = "返回的状态吗：200代表成功 500代表失败")
    private int code;
    @ApiModelProperty(value = "返回的的成功表示：true代表成功，false代表失败")
    private boolean success;
    @ApiModelProperty(value = "返回的实体")
    private T data;
    @ApiModelProperty(value = "返回的错误信息")
    private String errorMsg;

    public static  <T>  Result<T> success(T data) {
        Result<T> result = new Result<>();
        result.setData(data);
        result.setCode(200);
        result.setSuccess(true);
        return result;
    }
    public static  <T>  Result<T> failure(String errorMsg) {
        Result<T> result = new Result<>();

        result.setCode(500);
        result.setSuccess(false);
        result.setErrorMsg(errorMsg);
        return result;
    }

}
